<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // Symbol的意义防止重名,为了防止代码或者属性被覆盖
        //1、symbol作为属性的应用
        let keys={
            name:Symbol('name'),
            age:Symbol('age'),
            location:Symbol('location'),
            test:Symbol('test')
        }
        let obj={
            [keys.name]:'xcy',
            [keys.age]:100,
            [keys.location]:'asfasf',
            [keys.test](){
                console.log('Symbol成功')
            }
        }
        obj.name='sdfsdf'
        obj[keys.test]()
        console.log(obj)
        console.log(Reflect.ownKeys(obj))
        Reflect.ownKeys(obj).forEach((item,index)=>{
            console.log(item,obj[item])
        })

        // 2、symbol作为常量的应用
        const a=Symbol()
        const b=Symbol()
        function obj2(c){
            switch(c){
                case a:
                    console.log('aaa')
                    break
                case b:
                    console.log('bbb')
                    break
                default:
                    console.log('default')
            }
        }
        obj2(a)
    </script>
</body>
</html>